package com.gzbsoft.sc.modules.sys.entity;
import com.gzbsoft.sc.common.validator.group.AddGroup;
import com.gzbsoft.sc.common.validator.group.UpdateGroup;
import io.ebean.annotation.DbComment;
import io.ebean.annotation.DocStore;
import lombok.*;

import javax.persistence.*;
import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import java.util.List;
@DocStore
@Entity
@EqualsAndHashCode(callSuper = true)
@Data
@Table(name = "sys_user")
@Builder
@NoArgsConstructor
@AllArgsConstructor
@DbComment("系统用户")
public class SysUser extends BaseEntity {
    @NotBlank(message = "用户名不能为空", groups = {AddGroup.class, UpdateGroup.class})
    private String username;
    @NotBlank(message = "密码不能为空", groups = AddGroup.class)
    private String password;
    private String salt;
    @NotBlank(message = "邮箱不能为空", groups = {AddGroup.class, UpdateGroup.class})
    @Email(message = "邮箱格式不正确", groups = {AddGroup.class, UpdateGroup.class})
    private String email;
    private String mobile;
    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(name = "ref_sys_user_role",
            joinColumns = {@JoinColumn(name = "sys_user_id")},
            inverseJoinColumns = {@JoinColumn(name = "sys_role_id")})
    private List<SysRole> roleList;
    public SysUser(Long id) {
        this.id = id;
    }
    @Override
    public String toString() {
        return "SysUser{" +
                "username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", salt='" + salt + '\'' +
                ", email='" + email + '\'' +
                ", mobile='" + mobile + '\'' +
                ", roleList=" + roleList +
                ", id=" + id +
                '}';
    }
}
